//
//  Tournament.m
//  PokerPlus
//
//  Created by Lv Changye on 11-7-29.
//  Copyright 2011年 139me. All rights reserved.
//

#import "Tournament.h"


@implementation Tournament
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [scroll release];
    [moneyLabel release];
    [moneyarray release];
    
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    if (scroll==nil) 
        scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(84, 232, 348, 31)];
    [scroll.layer setCornerRadius:2];
    scroll.showsHorizontalScrollIndicator=NO;
    scroll.backgroundColor=[UIColor clearColor];
    scroll.contentSize=CGSizeMake(116*6, 31);
    scroll.delegate=self;
    [self.view addSubview:scroll];
    
    for (int i=1; i<=4; i++) {
        UIButton *label=[UIButton buttonWithType:UIButtonTypeCustom];
        label.frame=CGRectMake(116*i, 0, 116, 31);
        label.tag=i;
        
        switch (i) {
            case 1:
                [label setTitle:@"$100" forState:UIControlStateNormal];
                break;
            case 2:
                [label setTitle:@"$1千" forState:UIControlStateNormal];
                break;
            case 3:
                [label setTitle:@"$5万" forState:UIControlStateNormal];
                break;
            case 4:
                [label setTitle:@"$100万" forState:UIControlStateNormal];
                break;
            
            default:
                break;
        }
        [label setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [label setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
        [label addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        label.titleLabel.font=[UIFont boldSystemFontOfSize:15];
        
        [scroll addSubview:label];
    }
    if (moneyarray==nil) 
        moneyarray=[[NSArray alloc]initWithObjects:@"100",@"1千",@"5万",@"100万",nil];
  
    [super viewDidLoad];
    NSLog(@"%d",[scroll retainCount]);
    // Do any additional setup after loading the view from its nib.
}
-(void)click:(UIButton *)sender{
    int i=sender.tag;
    [scroll scrollRectToVisible:CGRectMake((i-1)*116, 0, 348, 31) animated:YES];
    
    m=i-1;
}
//-(void)viewWillAppear:(BOOL)animated{
//    [super viewWillAppear:animated];
//}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (![scrollView isDecelerating]) {
        int i=scrollView.contentOffset.x/116+0.5;
        [scrollView scrollRectToVisible:CGRectMake(i*116, 0, 348, 31) animated:YES];
        m=i;
    }
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    int i=scrollView.contentOffset.x/116+0.5;
    [scrollView scrollRectToVisible:CGRectMake(i*116, 0, 348, 31) animated:YES];
    m=i;
}

- (void)viewDidUnload
{
      scroll=nil;
    [scroll release];
    [moneyLabel release];
    moneyLabel = nil;
    moneyarray=nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)startTourGame:(id)sender {
    NSLog(@"%d",m);
    [delegate startTourWithMoneyString:[moneyarray objectAtIndex:m]];
}
@end
